<?php

namespace app\index\controller;

use think\Controller;
use think\Request;
use app\index\model\Roles as rolesModel;
use think\Db;
class Roles extends Controller
{
    public function save()
    {
        //
    	$name = input('post.name');
    	$role = new rolesModel();
    	$role->name = $name;
    	$role->save();
    }
    
    public function update()
    {
        //
    	$name = input('post.name');
    	$id = input('post.id');
    	$role = rolesModel::get($id);
    	if($name){
    		$role->name = $name;
    	}
    	$role->save();
    }
    
    public function query()
    {
        //
    	$id = input('get.id');
    	$role = rolesModel::get($id);
		$permission = $role->permission;
    	return json($role);
    }
    public function queryAll()
    {
    	$role = Db::query('select * from roles');
    	return json($role);
    }
    public function delete()
    {
        //
    	$id = input('get.id');
    	$role = rolesModel::get($id);
    	$role->delete();
    }
}
